package de.fhhof.vinf.ssp.ticketcenter.servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.GregorianCalendar;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import de.fhhof.vinf.ssp.ticketcenter.helpers.ServletHelper;

/**
 * Servlet implementation class Index
 */
@WebServlet(description = "Hauptseite, die den Content inkludiert", urlPatterns = { "/Index" })
public class Index extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Index() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		GregorianCalendar tempStartDate = new GregorianCalendar();
		PrintWriter out = response.getWriter();
		String cssPath = request.getContextPath() + "/css/bsp.css";
		String headerPath = request.getContextPath() + "/images/header_v1.jpg";
		ServletHelper.printHeader(out, cssPath, headerPath);
		// Content
		this.getContent(request, response);
		// Loginpanel
		this.getLogin(request, response);
		ServletHelper.printFooter(out, tempStartDate);
	}
	
	/**
	 * Inkludiert die Ausgabe des Servlet "LoginServlet".
	 * @param out	PrintWriter des Servlets, in den die Ausgabe geschrieben wird.
	 * @param response Response-Objekt des Servlets.
	 * @param request Request-Objekt des Servlets.
	 * @throws IOException 
	 * @throws ServletException 
	 */
	private void getLogin(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		ServletContext con = getServletContext();
		RequestDispatcher rq = con.getRequestDispatcher("/LoginServlet");
		rq.include(request, response);
		
	}

	/**
	 * Inkludiert die Ausgabe des Servlet "ContentServlet".
	 * @param out	PrintWriter des Servlets, in den die Ausgabe geschrieben wird.
	 * @param response Response-Objekt des Servlets.
	 * @param request Request-Objekt des Servlets.
	 * @throws IOException 
	 * @throws ServletException 
	 */
	private void getContent(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		RequestDispatcher rq = request.getRequestDispatcher("/ContentServlet");
		rq.include(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
